﻿function showMovieList() {
    var xhr = new XMLHttpRequest();
    xhr.onreadystatechange = function () {
        if (xhr.readyState == 4 && xhr.status == 200) {
            var response = JSON.parse(xhr.responseText).d;
            var length = response.length;
            var htmlString = "<ul>";
            for (var x = 0; x < length; x++) {
                htmlString += "<li>" + response[x].name + " (";
                htmlString += response[x].movieId + ")</li>";
            }
            htmlString += "</ul>";
            document.getElementById('output').innerHTML = htmlString;
        }
    };
    xhr.open('POST', 'AjaxTest.aspx/GetMovieList', true);
    xhr.setRequestHeader('Content-Type', 'application/json');
    xhr.send('{"director":"' + document.getElementById('ddl_Director').value + '"}');
}
function init() {
    document.getElementById('btn_GoTo').onclick = function () {
        showMovieList();
        return false;
    };
}
window.onload = init;